
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

interface IntegerStack {
	public Integer push(Integer item);

	public Integer pop();

	public Integer peek();

	public boolean empty();

	public int size();
}

class ArrayListIntegerStack implements IntegerStack {
	private List<Integer> list;

	public ArrayListIntegerStack() {
		list = new ArrayList<Integer>();
	}

	@Override
	public Integer push(Integer item) {
		if (item == null) {
			return null;
		}
		list.add(item);
		return item;
	}

	@Override
	public Integer pop() {
		if (list.isEmpty()) {
			return null;
		}
		return list.remove(list.size()-1);
	}

	@Override
	public Integer peek() {
		if (list.isEmpty())
			return null;
		return list.get(list.size()-1);
	}

	@Override
	public boolean empty() {
		if (list.isEmpty())
			return true;
		return false;
	}

	@Override
	public int size() {

		return list.size();
	}

	@Override
	public String toString() {
		return  list.toString() ;
	}
	
}

public class Main1 {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		ArrayListIntegerStack arraylistIntegerStack = new ArrayListIntegerStack();
		int m = scanner.nextInt();
		for (int i = 0; i < m; i++) {
			System.out.println(arraylistIntegerStack.push(scanner.nextInt()));
		}
		System.out.println(arraylistIntegerStack.peek() + "," + arraylistIntegerStack.empty() + "," + arraylistIntegerStack.size());
		System.out.println(arraylistIntegerStack);
		int x = scanner.nextInt();
		for (int i = 0; i < x; i++) {
			System.out.println(arraylistIntegerStack.pop());
		}
		System.out.println(arraylistIntegerStack.peek() + "," + arraylistIntegerStack.empty() + "," + arraylistIntegerStack.size());
		System.out.println(arraylistIntegerStack);
		scanner.close();
	}
}